import axios from 'axios'

let error = console.error

const api = '/brands'

export function getBrands (cb, fcb = () => error('getBrands')) {
  axios.get(api).then(res => {
    let data = res.data
    cb(data)
  }).catch(error => {
    fcb(error)
  })
}

export function addBrand (param, cb, fcb = () => error('addBrand')) {
  axios.post(api, param).then(res => {
    let data = res.data
    cb(data)
  }).catch(error => {
    fcb(error)
  })
}

export function editBrand (param, cb, fcb = () => error('editBrand')) {
  axios.put(api, param).then(res => {
    let data = res.data
    cb(data)
  }).catch(error => {
    fcb(error)
  })
}

export function deleteBrand (id, cb, fcb = () => error('deleteBrand')) {
  axios.delete(api + '/' + id).then(res => {
    let data = res.data
    cb(data)
  }).catch(error => {
    fcb(error)
  })
}
